1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * ParamSetMatcher.java
6    *
7    * Created on 13-Dec-2004 at 2:57:47 PM
8    */
9   package ca.uhn.cache.util;
10  
11  import org.jmock.core.Invocation;
12  import org.jmock.core.matcher.StatelessInvocationMatcher;
13  
14  import ca.uhn.cache.impl.StringSetParam;
15  
16  
17  /***
18   * Matcher for <code>StringSetParam</code>s.
19   * 
20   * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara</a>
21   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:01 $ by $Author: bryan_tripp $
22   */
23  public class StringSetParamMatcher extends StatelessInvocationMatcher {
24  
25      private final StringSetParam myParam;
26  
27      /***
28       * @param theParam The param this matcher will match against. 
29       */
30      public StringSetParamMatcher( StringSetParam theParam ) {
31          myParam = theParam;
32      }
33  
34      /***
35       * {@inheritDoc}
36       */
37      public boolean matches( Invocation theInvocation ) {
38          boolean retVal = false;
39          
40          if ("chunk".equals( theInvocation.invokedMethod.getName() )
41           && theInvocation.parameterValues.size() == 1 ) {
42              
43              if ( theInvocation.parameterValues.get(0) instanceof StringSetParam ) {
44                  StringSetParam param = (StringSetParam) theInvocation.parameterValues.get(0);
45                  retVal = myParam.intersects(param);
46              }
47          }
48          
49          return retVal;
50      }
51  
52      /***
53       * {@inheritDoc}
54       */
55      public StringBuffer describeTo( StringBuffer theBuffer ) {
56          return new StringBuffer( 
57                  "Matches against StringSetParam( " 
58                 + myParam 
59                 + " )" );
60      }
61  
62  }